class: title-slide, right, top background-image: url(data:image/png;base64,#img/horn.JPG) background-position: 90% 75%, 75% 75% background-size:cover .left-column[ # GRS Workshop<br>Introduction to ggplot ] .right-column[ ### maps **Eugene Hickey**<br> March 14th 2023 ] .palegrey[.left[.footnote[Graphic by [Elaine Hickey](https://photos.google.com/photo/AF1QipMjKNoaxyne8nte4HmxA6Th9-4fUfSbl_mx-_1G)]]] ??? Welcome to the workshop on ggplot. Where we'll show you how to create impressive data visualisations. --- layout: true <a class="footer-link" href="http://grs-2023.netlify.app">GRS 2023 — Eugene Hickey</a> <!-- this adds the link footer to all slides, depends on footer-link class in css--> --- class: center, inverse # <p style="font-family:'Cabin Sketch'">Maps in R</p> <br> # Maps <br> ### Vibrant area of development in R ### Large, and growing, number of packages available ### And, both fun and fascinating --- ## We'll begin by looking at some maps, to get a flavour of what R can do ## Then we'll discuss how it does it --- - drawing maps from google, different map types - maps of Dublin in terrain, satellite, and roadmap - adding layers to our maps - Irish small airport locations - doing some statistics on our maps - where are Irish schools concentrated? - incidence of violence in counties of Sao Paulo - using facets in maps - GDP in European countries - interactive maps - meteor locations - world projections --- # Data with Location Information ```r # airports <- read_csv("http://data-osi.opendata.arcgis.com/datasets/1ace692fe9fd4a648ee78347ad571de2_22.csv") # airports %>% # select(X, Y, Airport = NAMN1) %>% # head(10) %>% # kable() %>% # kable_styling(bootstrap_options = c("striped", "hover", "condensed")) ``` --- ## Some Examples of Maps <img src="data:image/png;base64,#06-maps_files/figure-html/map1-1.png" style="display: block; margin: auto;" /> --- ## Some Examples of Maps <img src="data:image/png;base64,#06-maps_files/figure-html/map2-1.png" style="display: block; margin: auto;" /> --- ## Some Examples of Maps <img src="data:image/png;base64,#06-maps_files/figure-html/map3-1.png" style="display: block; margin: auto;" /> --- ## Maps with Added Layers --- --- <img src="data:image/png;base64,#06-maps_files/figure-html/map6-1.png" style="display: block; margin: auto;" /> --- ## Maps Layout of Plots - geofacet <!-- --> --- ## Interactive Maps with leaflet()
--- ## Cartograms - Distort Size (and Shape) to Correspond to some Variable - Map of US income where each state has an area proportional to its population --- ## Mercator <img src="data:image/png;base64,#06-maps_files/figure-html/mercator-1.png" style="display: block; margin: auto;" /> --- ## Mollweide <!-- --> --- ##Interrupted Goode Homolosine <!-- --> --- ## Packages for Drawing Maps - lots of packages ('cus lots of people interested) - *ggmap* - useful for drawing maps with layers - *leaflet* -useful for interactive maps - *tmap* - useful for both, this is the one to use - see [vignette](https://cran.r-project.org/web/packages/tmap/vignettes/tmap-getstarted.html) for instructions --- ## Types of Maps - Two main categories - shapefiles - rasters - shapefiles are composed of geometical objects of points, lines or polygons - rasters are arrays of pixels essentially - we've used shapefiles here - new format called *sf* replacing *sp* --- ## Some Libraries for Maps - the ones mentioned above, *ggmap*, *leaflet*, and *tmap* - *sf* for layers like *geom_sf()* - *sp* still useful for legacy reasons - *spData* has lots of shapefiles - *rworldmap*, likewise --- ## Some Libraries for Maps - *rnaturalearth* - *rnoaa* for weather data - *RgoogleMaps* is the gateway to all the maps.google stuff - but you have to register now to get all this - *usmap*, kind of what it suggests - *albersusa*, shapefile projection of the US - can also google __shapefile__ plus some area to see what you get - *osmdata* gives access to open street map data --- ## More Involved Packages - *RQGIS* is an R interface for a _Graphical Information System_ - *spatstat* is for spatial statistics - clustering, correlations, point pattern analysis, kriging, etc - one of the largest libraries in all of R - *RSAGA* for geoprocessing and terrain analysis - *SPADAR* for astronomical mapping --- ## Some Nice Add on Libraries - *ggsn*, we used this to get a scale bar and compass for Sao Paolo - *ggspatial* likewise - *geofacet* for the European GDP plot - *ggrepel* for nice labelling in plots --- ## Some Resources - book by [Wilke](https://serialmentor.com/dataviz/) has a chapter on maps - several of maps above taken from [here](https://github.com/clauswilke/dataviz/blob/master/geospatial_data.Rmd) - article by [littlemissdata](https://www.littlemissdata.com/blog/ggmap-updated) uses *ggmap* - also includes instructions to register to access *get_googlemap()* - online book on [Geocomputation with R](https://geocompr.robinlovelace.net/) - list of [Coordinate Reference Systems](https://spatialreference.org/) - article on using [Open Street Map Data](https://dominicroye.github.io/en/2018/accessing-openstreetmap-data-with-r/) - tutorial from the [University of Chicago](https://spatialanalysis.github.io/) ---